﻿using System.Data.Common;

namespace CavemanTools.Sql
{
	/// <summary>
	/// Base class for an Ado.Net repository
	/// </summary>
	public abstract class AGenericRepository
	{
		protected const string SqlServerProvider = "System.Data.SqlClient";
		private string cnx;
		private DbProviderFactory factory;
		
		/// <summary>
		/// 
		/// </summary>
		/// <param name="provider">Db Provider</param>
		/// <param name="connection">Connection string</param>
		protected AGenericRepository(string provider,string connection)
		{
			cnx = connection;
			factory = DbProviderFactories.GetFactory(provider);
		}

		protected DbConnection Connect()
		{
			var s = factory.CreateConnection();
			s.ConnectionString = cnx;
			return s;
		}
	}
}
